<template>
  <div v-show="show">
    <a-dropdown>
          <span class="print-table" @click="printTable">
            学生名单导出 <a-icon type="down"/>
          </span>
      <a-menu slot="overlay">
        <a-menu-item>
          <span @click="printTable">课表打印</span>
        </a-menu-item>
        <a-menu-item>
          <span @click="exportTable('png')">导出png</span>
        </a-menu-item>
        <a-menu-item>
          <span @click="exportTable('excel')">导出excel</span>
        </a-menu-item>
      </a-menu>

    </a-dropdown>
    <a-table :columns="columns" :data-source="students" bordered :pagination="false" :scroll="{ y: 320 }">
      <template slot="title">
        <div style="text-align:center;font-size:18px">选课学生</div>
      </template>
      <template slot="footer">
        共有{{ studentNum }}名学生选课
      </template>
    </a-table>
  </div>
</template>

<script>

import {getCourseInfo} from "@/api/teacher/courseInfo"
import {querySelection} from "@/api/teacher/querySelection";
import {columns} from "@/pages/classInfo/js/studentColumns";


export default {
  "name": "sessionStudents",
  props: {
    courseItem: Object,
    show: Boolean,
  },
  data() {
    return {
      columns: [],
      course: this.courseItem,
      courseInfo: {},
      studentNum: -1,
      students: []
    }
  },
  mounted() {
    this.columns = columns.studentsColumns;
    this.getStudents();
  },
  methods: {
    getCourseInfo() {
      let self = this;
      getCourseInfo(self.course.courseId).then(res => {
        if (res.result) {
          self.courseInfo = res.courseInfo;
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    getStudents() {
      let self = this;
      querySelection(this.course.courseId).then(res => {
        if (res.result) {
          self.studentNum = res.total;
          self.students = res.nameList;
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    exportTable() {
      // 导出课表
      this.$message.info("功能正在开发")
    },
    printTable() {
      // 打印选课名单
      // let subOutputRankPrint = document.getElementById('table');
      // let newContent = subOutputRankPrint.innerHTML;
      // let oldContent = document.body.innerHTML;
      // document.body.innerHTML = newContent;
      window.print();
      //window.location.reload();
      // document.body.innerHTML = oldContent;
    },
  }
}
</script>

<style scoped>
.print-table{
  font-size: small;
  cursor: pointer;
  margin-left: 10px;
  color: blue;
}
</style>

